<?php 
//facebook/f_authenticate.php

//**	Facebook Authentication Script
//**	Call this page when you wish to require the "Login" button

if(!isset($authorizedPage))
	require('../error.php');
	
else{ ?>

<div id="fb-authenticate">

<script>
function fbLogout() {
        FB.logout(function (response) {
            //Do what ever you want here when logged out like reloading the page
            window.location.reload();
        });
    }
</script>

<?php

	if($user){
		echo '<span id="fbLogout" onclick="fbLogout()"><a class="fb_button fb_button_medium"><span class="fb_button_text">Logout</span></a></span>';
		echo "\n<div class=\"wrap\"><div class=\"wrapImage\"><img src=\"http://graph.facebook.com/{$user_profile['id']}/picture?type=normal&height=104\" id=\"fb_pic\"/></div>";
		echo "\n<div id=\"userwelcome\"><div>{$user_profile['first_name']} {$user_profile['last_name']}</div>";
		echo "\n<span><a href=\"account.php?ID={$user_profile['id']}\">My Account</a> <a href=\"#\">Help</a> <a href=\"#\">Privacy</a></span>";
		echo "\n</div></div>";
	}
	else{
		echo '<span id="fbLogout"><fb:login-button></fb:login-button></span>';
		echo "\n<div class=\"wrap\"><div class=\"wrapImage\"><img src=\"images/facebooksill.png\" id=\"fb_pic\"/></div>";
		echo "\n<div id=\"userwelcome\"><div>Log in to start creating today!</div>";
		echo "\n<span><a href=\"account.php?ID=-1\">My Account</a> <a href=\"#\">Help</a> <a href=\"#\">Privacy</a></span>";
		echo "\n</div></div>";
	}
	?>

	<div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>',
          cookie: true,
          xfbml: true,
          oauth: true
        });
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });
      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
</div>

<?php
}
?>